package com.leetcode.p200;

import com.bean.TreeNode;
import com.utils.DataUtils;
import com.utils.TreeUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

public class Test257 {

    public List<String> binaryTreePaths(TreeNode root) {
        List<String> res = new ArrayList<>();

        help(res, root, "");

        return res;
    }

    private void help(List<String> res, TreeNode root, String currentString) {
        if (root == null) {
            return;
        }

        if (Objects.equals(currentString, "")) {
            currentString = root.val + "";
        } else {
            currentString += "->" + root.val;
        }
        if (root.left == null && root.right == null) {
            res.add(currentString);
        } else {
            help(res, root.left, currentString);
            help(res, root.right, currentString);
        }
    }

    public static void main(String[] args) {
        TreeNode treeNode = TreeUtils.buildTree();
        Test257 test = new Test257();
        DataUtils.printListString(test.binaryTreePaths(treeNode));
    }
}
